package locks.dead.cooperating;

import annotation.GuardedBy;
import locks.entity.Point;

public class Taxi {

    @GuardedBy("this")
    private Point location, destination;
    private final Dispatcher dispatcher;

    private String name;

    public Taxi(Dispatcher dispatcher,String name) {
        this.dispatcher = dispatcher;
        this.name=name;
    }

    public synchronized Point getLocation() {
        return location;
    }

    /**
     * 查看出租车位置 如果达到指定集合地点那么 通知车队
     * @param location
     */
    public synchronized void setLocation(Point location) {
        this.location = location;
        if (location.equals(destination))
            dispatcher.notifyAvailable(this);
    }

    public synchronized Point getDestination() {
        return destination;
    }

    public synchronized void setDestination(Point destination) {
        this.destination = destination;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}